<?php
namespace app\servergoods\service\goods;

use \app\manage\service\ApiBase;

/**
 * @author:      李颖
 * @DateTime:    2017-05-31 16:29:22
 * @Description: 商品模块
 */
class Goods extends ApiBase
{
    protected $cateAttrsLogic = 'app\servergoods\logic\GoodsCategoryAttrs';
    protected $goodsLogic = 'app\servergoods\logic\Goods';
    protected $goodsValidate = 'app\servergoods\validate\Goods';


    use \app\serversetting\traits\AddCheckAppId;

    /*卖家添加或编辑商品*/
    protected function _yayiUpdateGoods($data, bool $isEdit): array 
    {
        $scene = $isEdit ? 'editGoods' : '';

        $validate = validate($this->goodsValidate);
        if(!$validate->scene($scene)->check($data)){
            return verify_err(null, $validate->getError());
        }

        //检验卖家和商品可操作性
        if($isEdit){
            $checkSeller = $this->_checkSellerGoods($data, 'edit');
            if($checkSeller['status'] != SUCCESS_STATUS){
                return $checkSeller;
            }
        }

        //检验 orther_info
        if( !$isEdit || ($isEdit && isset($data['orther_info']) && $data['orther_info']) ){
            if(!$validate->scene('checkOrtherInfo')->check($data['orther_info'])){
                return verify_err(null, $validate->getError());
            }  
        }

        //检查商品属性传值是否正确
        if( !$isEdit || ($isEdit && isset($data['goods_attrs']) && $data['goods_attrs']) ){
            $checkAttrsRes = $this->checkGoodsAttrs($data);
            if($checkAttrsRes['status'] != SUCCESS_STATUS){
                return $checkAttrsRes;
            }
            $data['goods_attrs'] = $checkAttrsRes['res']['newGoodsAttrs'];
            $data['search_fields'] = $checkAttrsRes['res']['searchFields'];  
        }

        //添加或编辑商品时  检验商品分类与app_id
        if( !$isEdit || ($isEdit && isset($data['cate_id']) && $data['cate_id']) ){
            $checkAppId = $this->_addCheckAppId(['app_id'=>$data['app_id'],'cate_id'=>$data['cate_id']], logic('\app\servergoods\logic\GoodsCategory'), 'dbOneCateInfo', 'cate_id');
            if($checkAppId['status'] != SUCCESS_STATUS){
                return $checkAppId;
            }
        }
        if($isEdit){
            return $this->logic($this->goodsLogic)->yayiEditGoods($data);   
        }else{
            return $this->logic($this->goodsLogic)->yayiAddGoods($data);
        }
       
    }

    /*亚数卖家发布商品*/
    public function yayiAddGoods(): array
    {

        $data = $this->haveIssetReceiveData(['app_id'=>0,'user_id'=>0,'cate_id'=>0,'title'=>' ','authors'=>'','imgs_urls'=>' ','imgs_ids'=>' ','price'=>0,'desc'=>' ','product_code'=>' ','goods_attrs'=>[],'organization'=>'','orther_info'=>[],'orther_price'=>'','profile_pic'=>'','number'=>1,'origin_number'=>1,'pay_method'=>0,
        'delivery_type'=>1,'delivery_area'=>'','province'=>0,'city'=>0,'county'=>0,'order'=>100,'start_time'=>0,'end_time'=>0,'seo_key'=>'']);

        return $this->_yayiUpdateGoods($data, false);

    }

    /*卖家编辑某个商品*/
    public function yayiEditGoods(): array 
    {

        $data = $this->issetReceiveData(['id'=>0, 'app_id'=>0, 'user_id'=>0, 'cate_id'=>0,'title'=>' ','authors'=>'','imgs_urls'=>' ','imgs_ids'=>' ','price'=>0,'desc'=>' ','product_code'=>' ','goods_attrs'=>[],'organization'=>'','orther_info'=>[], 'orther_price'=>'','profile_pic'=>'','number'=>1,'origin_number'=>1,'pay_method'=>0,
        'delivery_type'=>1,'delivery_area'=>'','province'=>0,'city'=>0,'county'=>0,'order'=>100,'start_time'=>0,'end_time'=>0,'seo_key'=>'']);

        return $this->_yayiUpdateGoods($data, true);
    }


    /*定义场景和验证字段 验证商品属性里面的值是否正确*/
    public function checkGoodsAttrs($data): array
    {
        //检验商品属性中是否传入改变价格的参数    影响价格是否导致商品价格为负数
        $allChangePrice = 0;
        $allChangeCurrency = 0;
        $attrData = $enName = $mustHaveDefault = $res = [];
        foreach ($data['goods_attrs'] as $k => $v) {
            if(!isset($v['en_name'], $v['value'])){ return verify_err(null, '请检查商品属性，属性名称与属性值必须传入'); }
            isset($v['change_price']) && $allChangePrice = bcadd($allChangePrice, $v['change_price']);
            isset($v['change_currency_price']) && $allChangeCurrency = bcadd($allChangeCurrency, $v['change_currency_price'], 4);
            $attrData[$v['en_name']][] = $v['value'];
            $enName[] = $v['en_name'];   //所传属性里的en_name数组
        }
        if(bcadd($data['price'], $allChangePrice) < 0){  return verify_err(null, '影响价格导致商品价格为负');  }
        //这里要检验最大积分抵扣值是否导致商品价格为负......
        $attrsList = $this->logic($this->cateAttrsLogic)->dbAttrsList(['en_name'=>['in',array_unique($enName)]]);
        foreach ($attrsList as $k => $v) {
            if($attrData[$v['en_name']] && in_array($v['attr_type'], ['3','4','5'])){
                if(!empty( array_diff($attrData[$v['en_name']], array_intersect(explode(",",$v['attr_values']),$attrData[$v['en_name']])) )){  return verify_err(null,'属性有误');  }
            }
            if($v['attr_type'] == 4){ $mustHaveDefault[] = $v['en_name']; } //必须传默认值的
            if($v['is_filter'] != 1){ unset($attrData[$v['en_name']]); }  //对arrData进行只保留参与搜索的字段
        }
        //检验必选项（必须有默认值的）是否都已设置了一个默认选项，且影响价格为0
        $defaultMustTrue = [];   //用来判断多选属性是否有且仅有一个默认值为1的项
        foreach ($data['goods_attrs'] as $k => $v) {
            if(in_array($v['en_name'], $mustHaveDefault)){   //attr_type为4 多选的
                if(!isset($v['change_price']) || !isset($v['change_currency_price'])){ return verify_err(null, '多选属性必须传入影响价格的字段'); }
                if(!isset($v['is_default'])){ return verify_err(null, '多选项属性必须有“标注是否为默认值”的字段！'); }
                !isset($defaultMustTrue[$v['en_name']]) && $defaultMustTrue[$v['en_name']] = 0;
                if($v['is_default'] == 1){ 
                    if($v['change_price'] != 0 || $v['change_currency_price'] != 0){  return verify_err(null, '默认值选项的影响价格必须为0！'); }
                    $defaultMustTrue[$v['en_name']] += 1;
                }
            }
        }
        foreach($defaultMustTrue as $k => $v){ if($v != 1){ return verify_err(null, '多选项必须有且仅有一个默认值'); }     }
        //重新组装goods_attrs
        $attrInfo = $this->logic($this->goodsLogic)->dealGoodsAttrs($attrsList, $data['goods_attrs']);
        if($attrInfo['status'] != SUCCESS_STATUS){ return $attrInfo; }
        $res['newGoodsAttrs'] = $attrInfo['res'];
        //获取search_fields 
        $res['searchFields'] = $this->logic($this->goodsLogic)->getSearchField($attrData);
        return auto_success($res,'属性验证无误');
    }

    /*---------获取商品详情开始------------------*/

    /*游客登录后获取商品详情*/
    public function goodsAllDetail(): array
    {
        $data = $this->haveIssetReceiveData(['id'=>0,'app_id'=>0, 'is_sell'=>'']);
        $map['status'] = 1;
        $map['is_del'] = 0;
        $map['number'] = ['gt', 0];
        return $this->_goodsPartInfo($data, $map);
    }
    /*未登录时获取商品详情 隐藏orther_info信息*/
    public function noLoginGoodsInfo(): array 
    {
        $data = $this->haveIssetReceiveData(['id'=>0,'app_id'=>0, 'is_sell'=>'']);
        $map['status'] = 1;
        $map['is_del'] = 0;
        $map['number'] = ['gt', 0];
        $res = $this->_goodsPartInfo($data, $map);
        isset($res['res']['orther_info']['user_phone']) && $res['res']['orther_info']['user_phone'] = substr($res['res']['orther_info']['user_phone'],0,3) . '*****' . substr($res['res']['orther_info']['user_phone'],-3);
        return $res;
    }
    /*获取我的某一商品详情*/
    public function myGoodsDetail(): array
    {
        $data = $this->haveIssetReceiveData(['id'=>0, 'user_id'=>0, 'is_sell'=>'']);
        $map['is_del'] = 0;
        return $this->_goodsPartInfo($data, $map);
    }
    /*管理员获取某一商品详情*/
    public function managerGoodsDetail(): array 
    {
        $data = $this->haveIssetReceiveData(['id'=>0,'app_id'=>0]);
        return $this->_goodsPartInfo($data);
    }
    /*私有方法获取商品详情*/
    protected function _goodsPartInfo(array $data, array $map = [], string $fields = '*'): array
    {
        $data['fields'] = $fields;
        $validate = validate($this->goodsValidate);
        if(!$validate->check($data)){
            return verify_err(null, $validate->getError());
        }
        return $this->logic($this->goodsLogic)->goodsDetail($data, $map);
    }

    /*---------获取商品详情结束------------------*/

    /*卖家删除商品*/
    public function sellerDelGoods(): array 
    {
        $data = $this->receiveData(['id'=>0,'user_id'=>0]);

        $validate = validate($this->goodsValidate);
        if(!$validate->scene('sellerOperaGoods')->check($data)){
            return verify_err(null, $validate->getError());
        }

        $checkSeller = $this->_checkSellerGoods($data);
        if($checkSeller['status'] != SUCCESS_STATUS){
            return $checkSeller;
        }

        return $this->logic($this->goodsLogic)->sellerDelGoods($data);
        
    }

    /*卖家下架某一个商品*/
    public function sellerSoldOutOne(): array 
    {
        $data = $this->receiveData(['id'=>0,'user_id'=>0]);

        $validate = validate($this->goodsValidate);
        if(!$validate->scene('sellerOperaGoods')->check($data)){
            return verify_err(null, $validate->getError());
        }

        $checkSeller = $this->_checkSellerGoods($data, 'soldOut');
        if($checkSeller['status'] != SUCCESS_STATUS){
            return $checkSeller;
        }

        return $this->logic($this->goodsLogic)->sellerSoldOutOne($data);
        
    }

    /*卖家操作某个商品时，判断某个商品是否可被操作 $data['id'] = 3 */
    protected function _checkSellerGoods(Array $data, $operate = ''): array 
    {
        $goodsInfo = $this->logic($this->goodsLogic)->dbOneGoodsInfo(['id'=>$data['id']]);
        if(!$goodsInfo || $goodsInfo['is_del'] != 0){
            return verify_err(null,'该商品不存在');
        }
        if($goodsInfo['user_id'] != $data['user_id']){
            return verify_err(null,'该商品不属于您');
        }
        if($operate == 'edit'){    //编辑商品
            if($goodsInfo['status'] != 2){
                return verify_err(null,'审核失败的商品才可重新编辑');
            }
        }elseif($operate == 'soldOut'){
            if(!in_array($goodsInfo['status'], ['1','4'])){
                return verify_err(null,'当前该商品状态不可下架');
            }
        }

        return auto_success(null,'商品属于该卖家');
    }

    /*管理员批量操作商品时，对商品批量检验是否可被操作 $data['id'] = [1,3] */
    protected function _adminBatchCheckGoods(Array $data, $operate = ''): array 
    {
        $goodsList = $this->logic($this->goodsLogic)->dbGoodsList(['id'=>$data['id']]);
        if(count($goodsList) == 0){
            return verify_err(null,'没有要操作的商品');
        }
        if(count($goodsList) != count($data['id'])){
            return verify_err(null,'其中包含不存在的商品');
        }
        foreach ($goodsList as $k => $v) {
            if($operate == 'manageBatchAuditGoods' && $v['status'] != 0){
                return verify_err(null,'失败！标题为'.$v['title'].'的商品不可审核');
            }
            if($operate == 'manageBatchSoldOutGoods' && !in_array($v['status'], ['1','4'])){
                return verify_err(null,'失败！标题为'.$v['title'].'的商品不可下架');
            }
        }
        return auto_success(null,'该批商品可被操作');

    }

    /*管理员删除商品*/
    public function manageDelGoods(): array 
    {
        $data = $this->receiveData(['id'=>0,'app_id'=>0]);
        return $this->stepRun($data,'manageDelGoods','manageOperaGoods');
    }

    /*管理员批量删除商品*/
    public function manageBatchDelGoods(): array 
    {
        $data = $this->receiveData(['id'=>[],'app_id'=>0]);
        return $this->stepRun($data,'manageDelGoods','manageBatchOperaGoods');
    }

    /*获取该平台状态为通过的商品总量*/
    public function goodsCount(): array 
    {
        $map = $this->haveIssetReceiveData(['app_id'=>0]);
        $map['status'] = 1;
        return $this->_goodsCount($map);
    }

    /*根据条件获取商品总量*/
    protected function _goodsCount($map = []): array 
    {
        return $this->stepRun($map, 'goodsCount');
    }
    
    /*管理员审核某一个商品*/
    public function auditOneGoods(): array 
    {

        $data = $this->receiveData(['id'=>0,'status'=>0,'app_id'=>0]);
        $data['id'] = [$data['id']];
        return $this->_adminBatchOperaGoods($data, 'manageBatchAuditGoods');

    }

    /*管理员审核某一批商品*/
    public function batchAuditGoods(): array 
    {

        $data = $this->receiveData(['id'=>[],'status'=>0,'app_id'=>0]);
        return $this->_adminBatchOperaGoods($data, 'manageBatchAuditGoods');

    }
    
    /*管理员下架某一个商品*/
    public function soldOutOneGoods(): array 
    {
        $data = $this->receiveData(['id'=>0,'app_id'=>0]);
        $data['id'] = [$data['id']];
        $data['status'] = 3;
        return $this->_adminBatchOperaGoods($data, 'manageBatchSoldOutGoods');
    }

    /*管理员下架某一批商品*/
    public function soldOutBatchGoods(): array 
    {
        $data = $this->receiveData(['id'=>0,'app_id'=>0]);
        $data['status'] = 3;
        return $this->_adminBatchOperaGoods($data, 'manageBatchSoldOutGoods');
    }

    /*管理员批量操作（审核、下架）商品,不包含删除*/
    protected function _adminBatchOperaGoods($data, $operate): array 
    {

        $validate = validate($this->goodsValidate);
        if(!$validate->scene($operate)->check($data)){
            return verify_err(null, $validate->getError());
        }

        $checkGoodsRes = $this->_adminBatchCheckGoods($data, $operate);
        if($checkGoodsRes['status'] != SUCCESS_STATUS){
            return $checkGoodsRes;
        }

        return $this->logic($this->goodsLogic)->batchOperaGoods($data, $operate);
    }

    /*获取商品列表*/
    protected function _goodsList($data): array 
    {

        $search = $this->issetReceiveData(['cate_id'=>0,'keywords'=>'','price_start'=>0,'price_end'=>0,'symbol'=>'','search_fields'=>[],'recommend'=>'','order'=>'']);
        $search && $data = array_merge($data, $search);

        $validate = validate($this->goodsValidate);
        if(!$validate->scene('getGoodsList')->check($data)){ return verify_err(null, $validate->getError()); }

        return $this->logic($this->goodsLogic)->goodsList($data);
    }

    /*卖家获取商品列表*/
    public function sellerGoodsList(): array 
    {
        $data = $this->receiveData(['user_id'=>0,'status'=>0,'page'=>1,'listRows'=>15,'app_id'=>0]);
        return $this->_goodsList($data);
    }

    /*管理员获取商品列表*/
    public function adminGoodsList(): array 
    {
        $data = $this->haveIssetReceiveData(['status'=>0,'page'=>1,'listRows'=>15,'app_id'=>0,'is_sell'=>'']);
        $data['is_del'] = ['neq',2];
        return $this->_goodsList($data);
    }

    /*前台个人艺术品商品列表 来自亚数平台*/
    public function personGoodsList(): array 
    {
        $data = $this->receiveData(['page'=>1,'listRows'=>15, 'app_id'=>0]);
        $data['status'] = 1;
        $data['is_sell'] = 0;
        $data['number'] = ['gt', 0];
        return $this->_goodsList($data);
    } 

    /*前台艺术馆商品列表 来自非亚数的其他平台*/
    public function goodsList(): array 
    {
        $data = $this->receiveData(['page'=>1,'listRows'=>15,'app_id'=>0]);
        $data['status'] = 1;
        $data['is_sell'] = 1;
        $data['number'] = ['gt', 0];
        return $this->_goodsList($data);
    } 

    /*未登录时的前台个人艺术品商品列表  隐藏部分字段 来自亚数平台*/
    /*public function noLoginPersonGoodsList(): array 
    {
        $data = $this->receiveData(['page'=>1,'listRows'=>15]);
        $data['status'] = 1;
        $data['is_sell'] = 0;
        $data['fields'] = 'id,user_id,cate_id,title,product_code,profile_pic,imgs_urls,imgs_ids,number,origin_number,price,orther_price,pay_method,delivery_type,delivery_area,view_times,create_time,start_time,end_time,seo_key,desc,goods_attrs,search_fields,recommend';
        return $this->_goodsList($data);
    }*/

    /*未登录时的前台艺术馆商品列表  隐藏部分字段 来自非亚数的其他平台*/
    /*public function noLoginGoodsList(): array 
    {
        $data = $this->receiveData(['page'=>1,'listRows'=>15]);
        $data['status'] = 1;
        $data['is_sell'] = 1;
        $data['fields'] = 'id,user_id,cate_id,title,product_code,profile_pic,imgs_urls,imgs_ids,number,origin_number,price,orther_price,pay_method,delivery_type,delivery_area,view_times,create_time,start_time,end_time,seo_key,desc,goods_attrs,search_fields,recommend';
        return $this->_goodsList($data);
    }*/

    /*前台获取所有商品的列表 来自所有平台*/
    public function allGoodsList(): array 
    {
        $data = $this->receiveData(['page'=>1,'listRows'=>15,'app_id'=>0]);
        $data['status'] = 1;
        $data['fields'] = 'id,user_id,cate_id,title,product_code,profile_pic,imgs_urls,imgs_ids,number,origin_number,price,orther_price,pay_method,delivery_type,delivery_area,view_times,create_time,start_time,end_time,seo_key,desc,goods_attrs,search_fields,recommend,origin_number-number AS sales';
        $data['number'] = ['gt', 0];
        return $this->_goodsList($data);
    }

    /*执行商品售空操作*/
    public function outOfStock(): array 
    {
        $data = $this->haveIssetReceiveData(['app_id'=>0]);
        return $this->stepRun($data, 'outOfStock');
    }

    /*管理员推荐某个商品*/
    public function recommend(): array 
    {
        $data = $this->haveIssetReceiveData(['id'=>0, 'recommend'=>'', 'app_id'=>0]);
        return $this->stepRun($data, 'recommend', 'recommend');
    }

    /*前台获取艺术馆商品价格的筛选项*/
    public function getPriceFilter(): array 
    {
        
        $data = $this->haveIssetReceiveData(['app_id'=>0]);
        $data['is_sell'] = 1;
        return $this->stepRun($data, 'getPriceFilter', '');
    }

    /*前台获取个人艺术品商品价格的筛选项*/
    public function getPersonPriceFilter(): array 
    {
        
        $data = $this->haveIssetReceiveData(['app_id'=>0]);
        $data['is_sell'] = 0;
        return $this->stepRun($data, 'getPriceFilter', '');
    }

    /*-------------------------------------艺货商品------------------------------------*/

    /*艺货的发布商品/修改商品的私有方法*/
    private function _yihuoUpdateGoods(array $data, bool $isEdit): array 
    {
        $scene = $isEdit ? 'yihuoEditGoods' : '';
        /*基本数据验证*/
        $validate = validate($this->goodsValidate);
        if(!$validate->scene($scene)->check($data)){ return verify_err(null, $validate->getError()); }
        //检验 orther_info
        if( !$isEdit || ($isEdit && isset($data['orther_info']) && $data['orther_info']) ){
            if(!$validate->scene('checkOrtherInfo')->check($data['orther_info'])){
                return verify_err(null, $validate->getError());
            }  
        }

        //检查商品属性传值是否正确
        if( !$isEdit || ($isEdit && isset($data['goods_attrs']) && $data['goods_attrs']) ){
            $checkAttrsRes = $this->checkGoodsAttrs($data);
            if($checkAttrsRes['status'] != SUCCESS_STATUS){
                return $checkAttrsRes;
            }
            $data['goods_attrs'] = $checkAttrsRes['res']['newGoodsAttrs'];
            $data['search_fields'] = $checkAttrsRes['res']['searchFields'];  
        }

        //添加或编辑商品时  检验商品分类与app_id
        if( !$isEdit || ($isEdit && isset($data['cate_id']) && $data['cate_id']) ){
            $checkAppId = $this->_addCheckAppId(['app_id'=>$data['app_id'],'cate_id'=>$data['cate_id']], logic('\app\servergoods\logic\GoodsCategory'), 'dbOneCateInfo', 'cate_id');
            if($checkAppId['status'] != SUCCESS_STATUS){
                return $checkAppId;
            }
        }
        if($isEdit){
            return $this->logic($this->goodsLogic)->yihuoEditGoods($data);   
        }else{
            return $this->logic($this->goodsLogic)->yihuoAddGoods($data);
        }

    }

    /*艺货后台发布商品*/
    /*相比于亚数，添加的字段如下：
    1、发布于谁人名下  2、积分最大抵扣值:integral_deduction（设置默认值为从配置文件读取） 3、亚数币总价:currency_price
    4、提货时间 5、最短交货周期 6、最长交货周期
    除了2放在商品属性里面，3放在other_price字段里面，其余的都常见，单独加个字段*/
    // v2: 去除亚艺币
    public function yihuoAddGoods(): array 
    {
        $data = $this->haveIssetReceiveData(['app_id'=>0,'user_id'=>0,'goods_belonger_name'=>' ','cate_id'=>0,'title'=>' ','authors'=>'','imgs_urls'=>' ','imgs_ids'=>' ','price'=>0,'desc'=>' ','product_code'=>' ','goods_attrs'=>[],'organization'=>'','orther_info'=>[],'profile_pic'=>'','origin_number'=>0,'pay_method'=>0,
        'delivery_type'=>1,'delivery_area'=>'','province'=>0,'city'=>0,'county'=>0,'order'=>100,'start_time'=>0,'end_time'=>0,'seo_key'=>'','pick_up_time'=>0,'start_delivery_time'=>0,'end_delivery_time'=>0,'latest_refund_time'=>0,'img_desc'=>'','text_desc'=>'']);
        $data['orther_price'] = ['currency'=>0];
        return $this->_yihuoUpdateGoods($data, false);  
    }

    /*艺货后台编辑商品*/
    public function yihuoEditGoods(): array 
    {
        $data = $this->issetReceiveData(['id'=>0,'app_id'=>0,'user_id'=>0,'goods_belonger_name'=>' ','cate_id'=>0,'title'=>' ','authors'=>'','imgs_urls'=>' ','imgs_ids'=>' ','price'=>0,'desc'=>' ','goods_attrs'=>[],'organization'=>'','orther_info'=>[],'profile_pic'=>'','number'=>0, 'origin_number'=>0,'pay_method'=>0,
        'delivery_type'=>1,'delivery_area'=>'','province'=>0,'city'=>0,'county'=>0,'order'=>100,'start_time'=>0,'end_time'=>0,'seo_key'=>'','pick_up_time'=>0,'start_delivery_time'=>0,'end_delivery_time'=>0,'latest_refund_time'=>0,'img_desc'=>'','text_desc'=>'']);

        return $this->_yihuoUpdateGoods($data, true);
    }

    /*前台获取某个推荐位下的商品列表  在newthink中进行获取某一个推荐位下的商品列表，再home或admin下再进行同时请求多个推荐位下的*/
    public function getRecommendList(): array 
    {
        $data = $this->haveIssetReceiveData(['app_id'=>0, 'cate_id'=>0, 'recommend'=>' ', 'limit'=>0, 'is_sell'=>'']);
        return $this->stepRun($data, 'getRecommendList', 'getRecommendList');
    }

    /*前台获取某个推荐位下的商品列表 */
    public function getRecommendPageList(): array 
    {
        $data = $this->haveIssetReceiveData(['app_id'=>0, 'cate_id'=>0, 'recommend'=>' ', 'page'=>1, 'listRows'=>15, 'is_sell'=>'']);
        $data['isPage'] = true;  //列表数据
        return $this->stepRun($data, 'getRecommendList', 'getRecommendList');
    }

    /*前台根据商品ids简单获取商品列表-中间方法调取*/
    public function getListByIds(): array 
    {
        $data = $this->haveIssetReceiveData(['app_id'=>0, 'goods_ids'=>' ']);
        return $this->stepRun($data, 'getListByIds');
    }

    /*艺货 - 获取艺术家的在售商品 不分页 只要为发布的商品，一律获取*/
    public function getArtistGoods(): array 
    {
        $data = $this->haveIssetReceiveData(['app_id'=>0, 'goods_belonger_name'=>' ', 'keywords'=>'', 'page'=>1, 'listRows'=>15]);
        return $this->stepRun($data, 'getArtistGoods');
    }

    /*艺货 - 添加一条与艺术家的账单*/
    public function addAccountBook(): array 
    {
        $data = $this->haveIssetReceiveData(['create_user_info'=>[], 'goods_id'=>0, 'order_number'=>0, 'total_price'=>0, 'remark'=>' ']);
        if(!isset($data['create_user_info']['id'], $data['create_user_info']['name'], $data['create_user_info']['nickname'])){
            return verify_err(null, '创建者信息不全');
        }
        return $this->stepRun($data, 'addAccountBook');
    }

    /*艺货 - 标注该账单已结算*/
    public function signSettlement(): array 
    {
        $data = $this->haveIssetReceiveData(['id'=>0, 'sign_settlement_user_info'=>[]]);
        if(!isset($data['sign_settlement_user_info']['id'], $data['sign_settlement_user_info']['name'], $data['sign_settlement_user_info']['nickname'])){
            return verify_err(null, '创建者信息不全');
        }
        return $this->stepRun($data, 'signSettlement');
    }

    /*艺货后台-获取所有账单分页数据*/
    public function allAccountBookList(): array 
    {
        $data = $this->haveIssetReceiveData(['page'=>1, 'listRows'=>15, 'keywords'=>'']);
        return $this->stepRun($data, 'allAccountBookList');
    }

    /*艺货前台-获取我艺术家身份的所有账单*/
    public function myAccountBookList(): array 
    {
        $data = $this->haveIssetReceiveData(['goods_belonger_name'=>' ', 'page'=>1, 'listRows'=>15, 'time'=>' ']);
        return $this->stepRun($data, 'myAccountBookList');
    }

    /*艺货前台-获取我艺术家某件商品的所有账单*/
    public function myGoodsAccountBookList(): array 
    {
        $data = $this->haveIssetReceiveData(['goods_belonger_name'=>' ', 'goods_id'=>0]);
        return $this->stepRun($data, 'myGoodsAccountBookList');
    }

    /*多个商品数量(剩余数量)-n*/
    public function descGoodsNumber(): array 
    {
        $data = $this->haveIssetReceiveData(['goods_info'=>[]]);
        foreach ($data['goods_info'] as $k => $v) {
            if(!isset($v['id']) || !isset($v['number'])){
                return verify_err(null, '请传入id和number');
            }
        }
        return $this->stepRun($data, 'descGoodsNumber');
    }

    /*多个商品数量（剩余数量）+n   取消订单以及订单超时时*/
    public function addGoodsNumber(): array 
    {
        $data = $this->haveIssetReceiveData(['goods_info'=>[]]);
        foreach ($data['goods_info'] as $k => $v) {
            if(!isset($v['id']) || !isset($v['number'])){
                return verify_err(null, '请传入id和number');
            }
        }
        return $this->stepRun($data, 'addGoodsNumber');
    }

    /*后台给某一个商品改价(人民币/亚数币)或增加库存*/
    public function changePriceNumber(): array 
    {
        $data = $this->haveIssetReceiveData(['app_id'=>0, 'id'=>0, 'price'=>'', 'currency'=>'', 'add_number'=>'']);
        if(!$data['price'] && !$data['currency'] && !$data['add_number']){
            return verify_err(null, '价格与库存增量必须填一个');
        }
        return $this->stepRun($data, 'changePriceNumber');
    }
    /*后台管理员批量修改艺货商品的价格 人民币价格与亚数币价格*/
    public function batchChangePrice(): array 
    {
        $data = $this->haveIssetReceiveData(['cate_id'=>'', 'multiple'=>1, 'currency_multiple'=>1]);
        return $this->stepRun($data, 'batchChangePrice');
    }
    //一周新增商品/总商品数量/在售商品数量
    public function goodsIncreTendency(): array 
    {
        $data = $this->haveIssetReceiveData(['dbDateFormat'=>'%y-%m-%d', 'dateFormat'=>'y-m-d']);
        return $this->stepRun($data, 'goodsIncreTendency');
    }

}